package com.liao.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.One;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lzp
 * @version 1.0
 * lzpnb!
 */
@Service
@Slf4j
public class MQSender {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(Object msg) {
        log.info("发送消息-->" + msg);
        rabbitTemplate.convertAndSend("queue",msg);
    }

    public void sendFanout(Object msg) {
        log.info("发送消息 ->" + msg);
        rabbitTemplate.convertAndSend("fanoutExchange","",msg);
    }


    public void sendDirect1(Object msg) {
        log.info("发送消息 ->" + msg);
        rabbitTemplate.convertAndSend("directExchange","queue.red",msg);
    }

    public void sendDirect2(Object msg) {
        log.info("发送消息 ->" + msg);
        rabbitTemplate.convertAndSend("directExchange","queue.green",msg);
    }

    public void sendTopic01(Object msg) {
        log.info("发送消息 ->" + msg);
        rabbitTemplate.convertAndSend("topicExchange","queue.red.message",msg);
    }

    public void sendTopic02(Object msg) {
        log.info("发送消息 ->" + msg);
        rabbitTemplate.convertAndSend("topicExchange","red.queue.red.message",msg);
    }

    public void sendHeaders01(String msg) {
        log.info("发送消息 ->" + msg);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("color","red");
        messageProperties.setHeader("speed","fast");
        Message message = new Message(msg.getBytes(), messageProperties);
        rabbitTemplate.convertAndSend("headersExchange","",message);
    }

    public void sendHeaders02(String msg) {
        log.info("发送消息 ->" + msg);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("color","red");
        messageProperties.setHeader("speed","normal");
        Message message = new Message(msg.getBytes(), messageProperties);
        rabbitTemplate.convertAndSend("headersExchange","",message);
    }

}
